<template>
  <div class="app-container">
    <div class="table_content">
      <headerSearch addTitle="添加合同" @handleAdd="handleAdd"
                    @creRefresh="getList"
                    :showSearch="false"></headerSearch>
      <!--表格渲染-->
      <el-table ref="table" v-loading="loading" :data="list" border style="width: 100%;" border
                :header-cell-style="{background: '#F8F8F9', color: '#515a6e',padding: '6px 0 !important'}">
        <af-table-column prop="leaseUnit" fixed="left" label="租赁单位" />
        <af-table-column prop="unitMan" label="租赁单位负责人" />
        <el-table-column prop="contractType" label="合同类型" min-width="110">
          <template slot-scope="scope">
            {{{'0':'招投标', '1':'非招投标'}[scope.row.contractType]}}
          </template>
        </el-table-column>
        <el-table-column prop="status" label="当前合同状态" min-width="120">
          <template slot-scope="scope">
            {{scope.row.status | statusFilters}}
          </template>
        </el-table-column>
        <af-table-column prop="startDate" label="合同开始日期" />
        <af-table-column prop="endDate" label="合同结束日期" />
        <af-table-column prop="signDate" label="合同签署日期" />
        <el-table-column prop="addTime" label="添加时间" min-width="140"/>
        <af-table-column prop="userName" label="添加用户名" />
        <el-table-column fixed="right" label="操作" min-width="100">
          <template slot-scope="scope">
            <el-button class="btn" type="text" size="small"
            @click="handleEdit(scope.$index,scope.row)">编辑</el-button>
            <el-popover
              placement="top"
              width="200"
              trigger="manual"
              :ref="'popover-' + scope.row.id">
              <p>确定删除该数据吗？</p>
              <div style="text-align: right; margin: 0">
                <el-button size="mini" type="text" @click="$refs[`popover-` + scope.row.id].doClose()">取消</el-button>
                <el-button type="primary" size="mini" @click="handleDel(scope.$index,scope.row)">确定</el-button>
              </div>
              <el-button class="btn" type="text" size="small" slot="reference"
                         @click="$refs[`popover-` + scope.row.id].doShow()">删除</el-button>
            </el-popover>
          </template>
        </el-table-column>
      </el-table>
      <!--分页-->
      <pagination v-show="total>0" :total="total"
                  :page.sync="listQuery.pageNum"
                  :limit.sync="listQuery.pageSize"
                  @pagination="getList" />
    </div>

    <!--表单添加-->
    <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" :close-on-click-modal="false">
      <el-form :model="editForm" :rules="editFormRules" ref="editForm" label-width="130px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="资产名称:" prop="assetID" class="form-item">
              <el-select placeholder="请选择" style="width:100%;" clearable v-model="editForm.assetID"
                         class="form-select" :popper-append-to-body="false" popper-class="select-popper">
                <el-option v-for="item in assetList" :value="asset.id" :label="item.assetName"></el-option>
              </el-select>
              <!--<el-input v-model="editForm.assetID" class="filter-item" placeholder="资产名称"/>-->
            </el-form-item>
            <el-form-item label="租赁/中标单位:" prop="leaseUnit" class="form-item">
              <el-input v-model="editForm.leaseUnit" class="filter-item" placeholder="租赁/中标单位"/>
            </el-form-item>
            <el-form-item label="租赁/中标单位负责:" prop="unitMan" class="form-item">
              <el-input v-model="editForm.unitMan" class="filter-item" placeholder="租赁/中标单位"/>
            </el-form-item>
            <el-form-item label="合同类型:" prop="contractType" class="form-item">
              <el-select placeholder="请选择" style="width:100%;" clearable v-model="editForm.contractType"
                         class="form-select" :popper-append-to-body="false" popper-class="select-popper">
                <el-option :value="0" label="招投标"></el-option>
                <el-option :value="1" label="非招投标"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="合同开始日期:" prop="startDate" class="form-item">
              <el-input v-model="editForm.startDate" class="filter-item" placeholder="合同开始日期"/>
            </el-form-item>
            <el-form-item label="合同结束日期:" prop="endDate	" class="form-item">
              <el-input v-model="editForm.endDate" class="filter-item" placeholder="合同结束日期"
                        type="textarea" :autosize="{ minRows: 1, maxRows: 4}"/>
            </el-form-item>
            <el-form-item label="合同签署日期:" prop="signDate	" class="form-item">
              <el-input v-model="editForm.signDate" class="filter-item" placeholder="合同签署日期"
                        type="textarea" :autosize="{ minRows: 1, maxRows: 4}"/>
            </el-form-item>
            <el-form-item label="文件" prop="fileName" class="form-item">
              <el-button class="btn-add" type="warning" size="mini"
                         icon="el-icon-upload" @click="upLoad">点击上传
              </el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click.native="dialogFormVisible=false">取消</el-button>
        <el-button type="primary" size="mini" @click="createData">
          {{dialogStatus == 'create'?'添加':'保存'}}
        </el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
  import { doPost, doGet, doFile, orglistChild } from '@/api/index'
  import Pagination from '@/components/Pagination/index'
  import headerSearch from '@/components/headerSearch/headerSearch'

  export default {
    name: "contract",
    components: {Pagination, headerSearch},
    data() {
      return{
        loading: false,
        showSearch: true,
        listQuery: {
          pageNum: 1,
          pageSize: 20,
          status: '',
          projectName: '',
          scale: ''
        },
        total: 0,
        list: [],
        dialogStatus: '',
        textMap:{
          update: '编辑',
          create: '新增'
        },
        dialogFormVisible: false,
        editForm: {
          leaseUnit: '',
          contractType: '',
          endDate: '',
          unitMan: '',
          startDate: '',
          signDate: '',
          assetID: '',
        },
        editFormRules: {
          orgName: [{ required: true, message: '请选择机构名称', trigger: 'blur' }],
          projectName: [{ required: true, message: '请填写项目名称', trigger: 'blur' }]
        },
        assetList: []
      }
    },
    created() {},
    methods: {
      getList() {},
      handleAdd() {
        this.dialogStatus = 'create'
        this.dialogFormVisible = true
        this.editForm = {
          leaseUnit: '',
          contractType: '',
          endDate: '',
          unitMan: '',
          startDate: '',
          signDate: '',
          assetID: '',
        }
        this.$nextTick(() => {
          this.$refs['editForm'].clearValidate()
        })
      },
      handleEdit(index,row) {},
      handleDel(index, row){},
      createData() {},
      upLoad() {}
    },
    filters: {
      statusFilters(val){
        return{
          '0':'合同签署',
          '1':'合同开始',
          '2':'合同自动结束',
          '3':'合同人为终止'
        }[val]
      }
    }
  }
</script>

<style lang="scss" scoped>

</style>
